package logic

import (
	"context"
	"jin-quan-dev/models/mysql"

	"jin-quan-dev/jinrpc/internal/svc"
	"jin-quan-dev/jinrpc/jinrpc"

	"github.com/zeromicro/go-zero/core/logx"
	"gorm.io/gorm"
)

type FormAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFormAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FormAddLogic {
	return &FormAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *FormAddLogic) FormAdd(in *jinrpc.FormAddRequest) (*jinrpc.FormAddResponse, error) {
	// todo: add your logic here and delete this line
	form := mysql.Form{
		Model: gorm.Model{},
		Title: in.Title,
		Area:  in.Area,
	}
	err := form.FormAdd(mysql.DB)
	if err != nil {
		return nil, err
	}
	return &jinrpc.FormAddResponse{
		FormId: int64(form.ID),
	}, nil
}
